package net.helix.ui.panels.library;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.tree.TreePath;

import net.helix.engine.library.LibraryTreeNode;

import org.jdesktop.swingx.JXTreeTable;

public class LibraryTreeTableMouseListener extends MouseAdapter {
	private LibraryPane libraryPane;
	public LibraryTreeTableMouseListener(LibraryPane libraryPane){
		super();
		this.libraryPane = libraryPane;
		
	}
	@Override
	public void mouseReleased(MouseEvent e) {
		
		Object src = e.getSource();
		if(src instanceof JXTreeTable) {
			JXTreeTable treeTable = (JXTreeTable) src;
			
			TreePath selectedPath = treeTable.getPathForRow(treeTable.getSelectedRow());
			if(selectedPath != null && selectedPath.getLastPathComponent() instanceof LibraryTreeNode){
				LibraryTreeNode node = (LibraryTreeNode) selectedPath.getLastPathComponent();
				if(node.id != LibraryTreeNode.FOLDER){
					libraryPane.changePreviewPicTo(node);
				}
				
			}
			
		}
		
		
		super.mouseReleased(e);
	}
	@Override
	public void mouseEntered(MouseEvent e){
		libraryPane.getTreeTableModel().isMouseOver = true;
	}
	@Override
	public void mouseExited(MouseEvent e){
		libraryPane.getTreeTableModel().isMouseOver = false;
		
	}
}
